//
// Created by shen on 2025/2/20.
//

#ifndef VIDEOEDIT_FFSEPERATOR_H
#define VIDEOEDIT_FFSEPERATOR_H
#include<thread>
#include "SLog.h"
#include <cstring>
#include <VideoPlayer.h>
#include "SeperatorTool.h"
#include "SWorkStatus.h"
#include "unistd.h"
#include "sys/sysinfo.h"
#include "libavcodec/avcodec.h"
#define MAX_PATH 1024
//#ifdef PLANTFORM
#define PLANTFORM
//  if(PLANTFORM==1){
#include "JavaCallHelper.h"
#include "LogUtil.h"
#include "AudioPlayer.h"
//  }
//#endif
extern "C"{
#include "libavformat/avformat.h"
#include "libavcodec/avcodec.h"
#include "libavcodec/bsf.h"

};
//#include "platform.h"
using namespace std;
class FFSeperator : public SeperatorTool{

private:
    static void  onPrepare(FFSeperator *mFFSeperator);
    static void  onStart(FFSeperator *mFFSeperator);
private:
    AVFormatContext *formatContext;
    char path[MAX_PATH] = {0};
    VideoPlayer *mVideoParam= nullptr;
    AudioPlayer *mAudioPalyer= nullptr;

public:
    FFStatus *ffStatus= nullptr;

    AVBSFContext *bsf_ctx=nullptr;
    std::thread *mTheadStart= nullptr;
    std::thread *mThreadPrepared= nullptr;

public:
    void prepare() override;
    void start() override;
public:

      FFSeperator(const char *url,FFStatus *ffStatus,JavaCallHelper *javaCallHelper);

    ~FFSeperator() override;





    void onDecodeReady();

    void initSeparator();

    int getAvcoeecContext(AVCodecParameters *avCodecParamters,AVCodecContext **avCodecContext);

    JavaCallHelper *getJavaCallHelper(){
        return javaCallHelper;
    }

    int64_t audioDuration = 0;

    int tempIndex = 0;

    JavaCallHelper *javaCallHelper;

};


#endif //VIDEOEDIT_FFSEPERATOR_H
